/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import com.sun.lwuit.Command;
import com.sun.lwuit.Form;
import com.sun.lwuit.Label;
import com.sun.lwuit.TextArea;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.layouts.BoxLayout;
import core.IMAPMIDlet;
import core.RuntimeData;
import core.ScreenEngine;
import network.Connection;
import network.PacketBuilder;
import view.commands.BackCommand;
import view.commands.EmptyCommand;

/**
 *
 * @author Kvest
 */
public class BaikalConfirmationForm extends BasicForm
{
    private static final int YES_COMMAND_ID = 1;
    
    public BaikalConfirmationForm()
    {
        super("confirmation");
               
        init();        
    }
    
    private void init()
    {
        setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        setCyclicFocus(false);
        
        TextArea text = new TextArea((new Label("b_c_t")).getText(), 1, 30);
        text.setEditable(false);
        text.setGrowByContent(true); 
        addComponent(text);
        
        addCommand(new EmptyCommand());
        addCommand(new BackCommand());
        
        Command yesCommand = new Command("yes", YES_COMMAND_ID)
        {
            public void actionPerformed(ActionEvent evt)
            {
                sendBaikalSignal();
                
                evt.consume();
            }
        };
        addCommand(yesCommand);
    }
    
    private void sendBaikalSignal()
    {
        //Формируем и отправляем запрос
        RuntimeData runtimeData = IMAPMIDlet.getMidlet().getRuntimeData();
        byte[] body = PacketBuilder.createDangerWarning(0, 0, runtimeData.getPeopleID());
        byte[] data = PacketBuilder.createSrvTransfereData(PacketBuilder.DEFAULT_CONNECTION_TYPE, runtimeData.getSrvID(), 
                                                           PacketBuilder.DEFAULT_DESTINATION_ID, runtimeData.getGUID(), true, body);
        Connection.getConnection().send(data);
        
        //Возвращаемся на главную форму
        ScreenEngine.getEngine().popTo(0); 
    }
}
